let app = (function () {
    let headers = {
    }
    let xhrFields = {
        withCredentials: true
    }
    let server = "http://localhost:3031"
    let baseUrl = `${server}/authentication`
    let socket = io(server, {transports: ['websocket']});
    let feathersClient = feathers()
        .configure(feathers.hooks())
        .configure(feathers.socketio(socket))
        .configure(feathers.authentication())

    function successCallback(data) {
        console.log(data)
    }
    function failedCallback(errorThrown) {
        console.warn(errorThrown)
    }
    return {
        socket,
        feathersClient,
        post: function (params, myUrl) {
            let method = "POST"
            let url = myUrl || baseUrl

            $.ajax({
                url: url,
                method: method,
                data: params,
                headers,
                xhrFields,
            })
                .done(function (data, textStatus, jqXHR) {
                    successCallback(data)
                })
                .fail(function (jqXHR, textStatus, errorThrown) {
                    failedCallback(textStatus)
                })
        },
        get: function (params, myUrl) {
            let method = "GET"
            let url = myUrl || baseUrl

            let keys = Object.keys(params)
            if (keys.length > 0) {
                url += '?'
                for (let k of keys) {
                    url += (k + '=' + dict[k])
                    url += '&'
                }
                url = url.substring(0, url.length - 1)
            }
            console.log(url)

            $.ajax({
                url: url,
                method: method,
                data: params,
                headers,
                xhrFields,
            })
                .done(function (data, textStatus, jqXHR) {
                    successCallback(data)
                })
                .fail(function (jqXHR, textStatus, errorThrown) {
                    failedCallback(textStatus)
                })
        },
        remove: function (params, myUrl) {
            let method = "REMOVE"
            let url = myUrl || baseUrl

            $.ajax({
                url: url,
                method: method,
                data: params,
                headers,
                xhrFields,
            })
                .done(function (data, textStatus, jqXHR) {
                    successCallback(data)
                })
                .fail(function (jqXHR, textStatus, errorThrown) {
                    failedCallback(textStatus)
                })
        }
    }
})()

console.log(app);